﻿using CarEdge.Infrastructure.Dto.Request.login;
using CarEdge.Infrastructure.Dto.Response.Org;
using CarEdge.Service.Interface;
using CarEdge.Service.Interface.Org;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace CarEdge.Admin.Controllers.ORG
{
    /// <summary>
    ///组织架构
    /// </summary>
    public class OrgController : BaseController
    {

        private readonly I_Org_EFCore _org_EFCore;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="login_Service"></param>
        /// <param name="i_Org_EFCore"></param>
        public OrgController(I_Login_Service login_Service,I_Org_EFCore i_Org_EFCore) : base(login_Service)
        {
            _org_EFCore = i_Org_EFCore;
        }


        /// <summary>
        /// 获取所有部门
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<IActionResult> Get_Dept()
        {
            var data = await _org_EFCore.Get_DepArtment();
            return Ok(data);
        }
        /// <summary>
        /// 获取所有职务
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Duty(int? page = 1, int? limit = 10, string? key = "")
        {
            var result = await _org_EFCore.Get_duty(page ?? 1, limit ?? 10, key ?? "");
            return Ok(result);
        }
       /// <summary>
       /// 获取当前部门下面的用户
       /// </summary>
       /// <param name="id">部门Id</param>
       /// <param name="page">显示的页数</param>
       /// <param name="limit">每页显示多少条数据</param>
       /// <param name="key">关键字</param>
       /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_DepUser(string? id,int? page = 1, int? limit = 10, string? key = "")
        {
            var result = await _org_EFCore.Get_DepUser(id!, page ?? 1, limit ?? 10, key ?? "");
            return Ok(result);
        }
        /// <summary>
        /// 删除职务
        /// </summary>
        /// <param name="dto">只需要传一个职务ID</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_Duty(Duty_Response_Dto dto)
        {
            var result = await _org_EFCore.Delete_Duty(dto.ids);
            return Ok(result);
        }
        /// <summary>
        /// 启用禁用
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Ban_Duty(Duty_Response_Dto dto)
        {
            var result = await _org_EFCore.Ban_Duty(dto.id!, dto.isban);
            return Ok(result);
        }
        /// <summary>
        /// 添加职务
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Duty(Duty_Response_Dto dto)
        {
            var result = await _org_EFCore.Add_Duty(dto.name!, dto.explain!,Convert.ToInt32(dto.lv));
            return Ok(result);

        }
        /// <summary>
        /// 获取单个职务详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Duty_Detail(string id)
        {
            var result = await _org_EFCore.Get_Duty_Detail(id);
            return Ok(result);
        }
        /// <summary>
        /// 禁用启用用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Ban_DepUser(User_Org_Response_Dto dto)
        {
            var result = await _org_EFCore.Ban_DepUser(dto);
            return Ok(result);
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_User(User_Org_Response_Dto dto)
        {
            var result = await _org_EFCore.Delete_User(dto);
            return Ok(result);
        }
        /// <summary>
        /// 修改用户部门
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update_UserDep(User_Org_Response_Dto dto)
        {
            var result = await _org_EFCore.Update_UserDep(dto);
            return Ok(result);
        }
        /// <summary>
        /// 获取当前部门的职务
        /// </summary>
        /// <param name="depid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_DepDuty(string uid)
        {
            var result = await _org_EFCore.Get_DepDuty(uid);
            return Ok(result);
        }
        /// <summary>
        /// 修改用户职务
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update_UserDuty(User_Org_Response_Dto dto)
        {
            var result = await _org_EFCore.Update_UserDuty(dto);
            return Ok(result);
        }
        /// <summary>
        /// 获取部门名称和当前部门的所有职务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Dept_DutyAll(string id)
        {
            var result = await _org_EFCore.Get_Dept_DutyAll(id);
            return Ok(result);
        }
        /// <summary>
        /// 根据部门id获取当前部门的所有职务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_DutyUser(string id)
        {
            var result = await _org_EFCore.Get_DutyUser(id);
            return Ok(result);
        }
        /// <summary>
        /// 获取部门的名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_DeptName(string id)
        {
            var result = await _org_EFCore.Get_DeptName(id);
            return Ok(result);
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_User(User_Response_Dto dto)
        {
            var result = await _org_EFCore.Add_User(dto);
            return Ok(result);
        }
        [HttpPost]
        public async Task<IActionResult> Add_Dept(Dept_Add_Response_Dto dto)
        {
            var result=await _org_EFCore.Add_Dept(dto);
            return Ok(result);
        }
        /// <summary>
        /// 部门
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_DeptNameLV(string id)
        {
            var result = await _org_EFCore.Get_DeptNameLV(id);
            return Ok(result);
        }
        /// <summary>
        /// 获取所有职务
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_AddDuty()
        {
            var result = await _org_EFCore.Get_AddDuty();
            return Ok(result);
        }
        /// <summary>
        /// 获取当前部门拥有的职务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_CheckDuty(string id)
        {
            var result = await _org_EFCore.Get_CheckDuty(id);
            return Ok(result);
        }
        [HttpPost]
        public async Task<IActionResult> update_dept(Dept_Update_Response_Dto dto)
        {
            var result = await _org_EFCore.update_dept(dto);
            return Ok(result);
        }
        [HttpPost]
        public async Task<IActionResult> Update_Duty(Duty_Update_Response_Dto dto)
        {
            var result=await _org_EFCore.update_duty(dto);
            return Ok(result);
        }
    }
}